const serverUrl = 'http://localhost:8088/api/'
function requestPromisify(fn) {
  return function (obj = {}) {
    return new Promise((resolve, reject) => {
      obj.success = function (res) {
        //成功
        resolve(res)
      }
      obj.fail = function (res) {
        //失败
        reject(res)
      }
      fn(obj)
    })
  }
}
function getRequest(url, data) {
  var getRequest = requestPromisify(wx.request)
  return getRequest({
    url: serverUrl+url,
    method: 'GET',
    data: data,
    header: {
      'Content-Type': 'application/json'
    }
  })
}
function postRequest(url, data) {
  var postRequest = requestPromisify(wx.request)
  return postRequest({
    url: serverUrl+url,
    method: 'POST',
    data: data,
    header: {
      "content-type": "application/json"
    },
  })
}
function putRequest(url, data) {
  var postRequest = requestPromisify(wx.request)
  return postRequest({
    url: serverUrl+url,
    method: 'PUT',
    data: data,
    header: {
      "content-type": "application/json"
    },
  })
}
module.exports = {
  requestPromisify: requestPromisify,
  getRequest: getRequest,
  postRequest: postRequest,
  putRequest: putRequest
}